#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: text_data.py
# Description: 
#   The type used to hold text is str, the type used to hold data is bytes. 
#   PEP 3120: The default source encoding is now UTF-8.
#   PEP 3131: Non-ASCII letters are now allowed in identifiers. 
#   The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.
# Edit History: 
#   2011-09-02    File created.
#===============================================================================

'''
2.7
'''
import urllib

url = "http://localhost"
#fp = urllib.urlopen(url)
#data = fp.read()
#print "%s, %s" % (type(data), type(data).__name__)  # <type 'str'>, str
#print data

'''
3.0
'''
import urllib.request

url = "http://localhost"
fp = urllib.request.urlopen(url)
data = fp.read()
print ("(data type, name) = (%s, %s)" % (type(data), type(data).__name__))  # (<class 'bytes'>, bytes)
#print (data)
data = str(data,'utf-8') # convert a byte datatype to string datatype using utf-8 encoding. For ASCII, data = str(data,'ascii')
print ("(data type, name) = (%s, %s)" % (type(data), type(data).__name__))  # (<class 'str'>, str)
#print (data)

你好 = "test"
print(你好)  # test
